package com.example.myobject.mapper;

import com.example.myobject.entity.dto.AdminDTO;
import com.example.myobject.entity.vo.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper {
    //添加管理员登录账户sql语句
    @Insert("insert into admin(id,username,password,nickname,description,is_enable) values(null,#{username},#{password},#{nickname},#{description},#{isEnable})")
    @Result(property = "isEnable",column = "is_enable")
    void insert(Admin admin);

    //管理员登录账号查询sql语句
    @Select("select * from admin where username=#{username}")
    //查询管理员信息方法
    Admin selectByUsername(String username);

    //管理员信息列表查询方法
    @Select("select id,username,password,nickname,description,is_enable from admin")
    //因为sql命名是以_划分,所以实际sql语句和java语句的名称不一致,需要修改
    @Result(property = "isEnable",column = "is_enable")
    List<AdminDTO> select();

    //管理员信息删除的方法
    @Delete("delete from admin where id=#{id}")
    void deleteById(int id);

    //管理员账号修改前的查询方法
    @Select("select id,username,password,nickname,description,is_enable from admin where id=#{id}")
    @Result(property = "isEnable",column = "is_enable")
    AdminDTO selectById(int id);

    //管理员修改账号信息的方法
    @Update("update admin set username=#{username},password=#{password},nickname=#{nickname},description=#{description}," +
            "is_enable=#{isEnable} where id=#{id}")
    void updateAdmin(AdminDTO adminDTO);
}
